package world.hezi.http;

import world.hezi.callback.BeatsaverHttpCallback;
import net.mamoe.mirai.contact.Contact;
import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import world.hezi.pools.JedisPools;
import redis.clients.jedis.Jedis;

import java.util.List;

public class GetBeatsaverLeast {
    private final List<Contact> contact;
    private Jedis jedis;

    public GetBeatsaverLeast(List<Contact> contact, Jedis jedis) {
        this.contact = contact;
        this.jedis = jedis;
    }

    public void getLeast(){
        if (!jedis.isConnected()||jedis.isBroken()){
            jedis = JedisPools.getJedis();
        }
        String url = "https://api.beatsaver.com/maps/latest?automapper=false&sort=CREATED";
        OkHttpClient okHttpClient = new OkHttpClient();
        final Request request = new Request.Builder()
                .url(url)
                .get()
                .build();
        Call call = okHttpClient.newCall(request);
        call.enqueue(new BeatsaverHttpCallback(contact,jedis));
    }
}
